﻿using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using System.Diagnostics;

namespace Love
{
    public partial class getLove : Form
    {
        public getLove()
        {
            InitializeComponent();
        }
        private string[] Love = //你要说的话
        {
            "1111111111",
            "22222222",
            "3333333333333",
            "点赞，收藏，投币，关注"
        };
        private int S = 0;
        private int sayID = 0;
        private void getLove_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = FormBorderStyle.None;     //设置窗体为无边框样式
            this.WindowState = FormWindowState.Maximized;    //最大化窗体 

            tblSay.Left = this.Width / 2 - tblSay.Width / 2;
            tblSay.Top = this.Height / 2 - tblSay.Height / 2;

            Control.CheckForIllegalCrossThreadCalls = false;

            bgw.RunWorkerAsync();
        }

        private void tblSay_Click(object sender, EventArgs e)
        {
            next();
        }

        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            tblSay.Text = "";
            if (sayID > Love.Length - 1) //结束啦
            {
                string dir = Application.ExecutablePath;
                DeleteItself(); ; //销毁自身
                Application.Exit();
            }
            else
            {
                writeStr(Love[sayID]);
            }
        }
        public void writeStr(string str)
        {
            char[] chs = str.ToCharArray();
            foreach (char item in chs)
            {
                tblSay.Text += item;
                Thread.Sleep(200);  //延迟时间
    }
        }

        private void tim5S_Tick(object sender, EventArgs e)
        {
            if (S <5)
            {
                S++;
            }
        }
        private void next()
        {
            if (S == 5)
            {
                sayID++;
                S = 0;
                bgw.RunWorkerAsync();
            }
        }

        private void getLove_Click(object sender, EventArgs e)
        {
            next();
        }
        /// <summary>
        /// 删除程序自身（本文地址：http://www.cnblogs.com/Interkey/p/DeleteItself.html）【推荐】
        /// </summary>
        private void DeleteItself()
        {
            string vBatFile = Path.GetDirectoryName(Application.ExecutablePath) + "\\DeleteItself.bat";
            using (StreamWriter vStreamWriter = new StreamWriter(vBatFile, false, Encoding.Default))
            {
                vStreamWriter.Write(string.Format(
                    ":del\r\n" +
                    " del \"{0}\"\r\n" +
                    "if exist \"{0}\" goto del\r\n" +
                    "del %0\r\n", Application.ExecutablePath));
            }

            //************ 执行批处理
            exeBat(vBatFile);
            //************ 结束退出
            Application.Exit();
        }

        private void exeBat(string path)
        {
            Process pro = new Process();
            pro.StartInfo.FileName = path;
            pro.StartInfo.UseShellExecute = false;
            pro.StartInfo.RedirectStandardInput = false;
            pro.StartInfo.RedirectStandardOutput = true;
            pro.Start();
        }
    }
}
